﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Campus {
    class Architect : Unit {
        public string BuildString = "";
        public bool IsBuilding;
        public bool IsAtBuildLocation;
        public Vector2 BuildDestination;

        static public List<Texture2D> IdleAnim = new List<Texture2D>();
        static public List<Texture2D> WalkRightAnim = new List<Texture2D>();
        static public List<Texture2D> WalkLeftAnim = new List<Texture2D>();
        static public List<Texture2D> WalkUpAnim = new List<Texture2D>();
        static public List<Texture2D> WalkDownAnim = new List<Texture2D>();
        static public List<Texture2D> AttackRightAnim = new List<Texture2D>();
        static public List<Texture2D> AttackLeftAnim = new List<Texture2D>();
        static public List<Texture2D> DieAnim = new List<Texture2D>();

        private void CreateAbilites() {
            Abilities.Add("Move", new MoveAbility(this, Vector2.Zero));
            Abilities.Add("Attack", new MeleeAttack(this, null, Ability.TargetTypes.BaseEntityTarget,
                1, 2, 1500));
            Abilities.Add("Build College of Architecture", new BuildStructureAbility(MenuIcons.AttackIcon, this, BuildRequirements.Buildings.CollegeOfArchitecture));
            Abilities.Add("Build Coffee Shop", new BuildStructureAbility(MenuIcons.AttackIcon, this, BuildRequirements.Buildings.CoffeeShop));
            this.CanAttack = true;
        }

        public Architect(Vector2 position, Player player, Level level) 
            : base(CreateDictionary(), position, 50, player, level, new Dictionary<String, Ability>(), 
            new Dictionary<string,AbilitySubMenu>())
        {
            m_name = "Architect";
            m_entitySelectedImage = IdleAnim[0];
            Size = new Vector2(50, 50);
            CreateAbilites();
        }

        public override void Update(GameTime gameTime, bool checkInput, bool updateBoundingBox)
        {
            if (IsBuilding && Position == Destination)
            {
                IsAtBuildLocation = true;
            }
            else 
            { 
                IsAtBuildLocation = false; 
            }

            base.Update(gameTime, checkInput, updateBoundingBox);
        }
        static private Dictionary<Unit.UnitState, Animation> CreateDictionary()
        {
            Dictionary<Unit.UnitState, Animation> dict = new Dictionary<UnitState, Animation>();

            // Creates an animation based on the certain static list, then adds it to the
            // Dictionary under the appropriate state.
            Random rgen = new Random();

            dict.Add(UnitState.Idle, new Animation(IdleAnim, rgen.Next(200, 300), true));
            dict.Add(UnitState.WalkRight, new Animation(WalkRightAnim, 75, true));
            dict.Add(UnitState.WalkLeft, new Animation(WalkLeftAnim, 75, true));
            dict.Add(UnitState.WalkDown, new Animation(WalkDownAnim, 50, true));
            dict.Add(UnitState.WalkUp, new Animation(WalkUpAnim, 50, true));
            dict.Add(UnitState.AttackRight, new Animation(AttackRightAnim, 150, false));
            dict.Add(UnitState.AttackLeft, new Animation(AttackLeftAnim, 150, false));
            dict.Add(UnitState.Die, new Animation(DieAnim, 150, false));

            return dict;
        }
        

        static public void InitializeAnimations(ContentManager Content)
        {
            // Loads all the idle animation frames
            IdleAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerIDLE_0"));
            IdleAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerIDLE_1"));
            IdleAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerIDLE_2"));
            IdleAnim.Add(IdleAnim[1]);

            // Loads all the walk left frames
            WalkLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKLEFT_0"));
            WalkLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKLEFT_1"));
            WalkLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKLEFT_2"));
            WalkLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKLEFT_3"));
            WalkLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKLEFT_4"));
            WalkLeftAnim.Add(WalkLeftAnim[3]);
            WalkLeftAnim.Add(WalkLeftAnim[2]);
            WalkLeftAnim.Add(WalkLeftAnim[1]);

            // Loads all the walk right frames
            WalkRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKRIGHT_0"));
            WalkRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKRIGHT_1"));
            WalkRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKRIGHT_2"));
            WalkRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKRIGHT_3"));
            WalkRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKRIGHT_4"));
            WalkRightAnim.Add(WalkRightAnim[3]);
            WalkRightAnim.Add(WalkRightAnim[2]);
            WalkRightAnim.Add(WalkRightAnim[1]);

            // Loads all the walk up frames
            WalkUpAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKUP_0"));
            WalkUpAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKUP_1"));
            WalkUpAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKUP_2"));
            WalkUpAnim.Add(WalkUpAnim[2]);
            WalkUpAnim.Add(WalkUpAnim[1]);
            WalkUpAnim.Add(WalkUpAnim[0]);
            WalkUpAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKUP_3"));
            WalkUpAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKUP_4"));
            WalkUpAnim.Add(WalkUpAnim[7]);
            WalkUpAnim.Add(WalkUpAnim[6]);
            WalkUpAnim.Add(WalkUpAnim[5]);

            // Loads all the walk down frames
            WalkDownAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKDOWN_0"));
            WalkDownAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKDOWN_1"));
            WalkDownAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKDOWN_2"));
            WalkDownAnim.Add(WalkDownAnim[2]);
            WalkDownAnim.Add(WalkDownAnim[1]);
            WalkDownAnim.Add(WalkDownAnim[0]);
            WalkDownAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKDOWN_3"));
            WalkDownAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerWALKDOWN_4"));
            WalkDownAnim.Add(WalkDownAnim[7]);
            WalkDownAnim.Add(WalkDownAnim[6]);
            WalkDownAnim.Add(WalkDownAnim[5]);

            // Loads all the attack right frames
            AttackRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKRIGHT_0"));
            AttackRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKRIGHT_1"));
            AttackRightAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKRIGHT_2"));

            // Loads all the attack left frames
            AttackLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKLEFT_0"));
            AttackLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKLEFT_1"));
            AttackLeftAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerATTACKLEFT_2"));

            // Loads all the death frames
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_0"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_1"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_2"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_3"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_4"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_5"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_6"));
            DieAnim.Add(Content.Load<Texture2D>("Units/Engineer/mechEngineerDEATH_7"));
        }
    }
}
